package com.bookyourtrek.action;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Date;

import org.joda.time.DateTime;
import org.joda.time.Days;

import com.bookyourtrek.model.ImageModel;
import com.bookyourtrek.model.ImagePojo;
import com.bookyourtrek.model.TicketModel;
import com.bookyourtrek.model.TicketPojo;
import com.bookyourtrek.model.TrekModel;
import com.bookyourtrek.model.TrekPojo;
import com.bookyourtrek.util.RuntimeSettings;
import com.opensymphony.xwork2.ActionSupport;

public class ViewAdventureAction extends ActionSupport{

	/**
	 * 
	 */
	private BigInteger adventureid;
	private Integer adventuretype;

	private ArrayList<TrekPojo> trekpojo = new ArrayList<TrekPojo>();
	private ArrayList<ImagePojo> imagepojo = new ArrayList<ImagePojo>();
	
	public ArrayList<TrekPojo> getTrekpojo() {
		return trekpojo;
	}
	public void setTrekpojo(ArrayList<TrekPojo> trekpojo) {
		this.trekpojo = trekpojo;
	}
	public ArrayList<ImagePojo> getImagepojo() {
		return imagepojo;
	}
	public void setImagepojo(ArrayList<ImagePojo> imagepojo) {
		this.imagepojo = imagepojo;
	}
	public ArrayList<TicketPojo> getTicketpojo() {
		return ticketpojo;
	}
	public void setTicketpojo(ArrayList<TicketPojo> ticketpojo) {
		this.ticketpojo = ticketpojo;
	}
	private ArrayList<TicketPojo> ticketpojo = new ArrayList<TicketPojo>();
	
	public BigInteger getAdventureid() {
		return adventureid;
	}
	public void setAdventureid(BigInteger adventureid) {
		this.adventureid = adventureid;
	}
	public Integer getAdventuretype() {
		return adventuretype;
	}
	public void setAdventuretype(Integer adventuretype) {
		this.adventuretype = adventuretype;
	}
	private static final long serialVersionUID = 1L;
	
	public String viewadventure() {
		
	
		
		//if trekking
		if (adventuretype == RuntimeSettings.EVENTTREKKING) {
			TrekModel trekmodel = new TrekModel();
			ImageModel imagemodel = new ImageModel();
			TicketModel ticketmodel = new TicketModel();
			trekpojo = trekmodel.gettrekdetails(adventureid);
			imagepojo = imagemodel.getimages(adventureid);
			ticketpojo = ticketmodel.getticket(adventureid, RuntimeSettings.EVENTTREKKING.toString());
			
			//ticket calculations
			for (int i=0; i<ticketpojo.size(); i++) {
				ticketpojo.get(i).setFee(ticketpojo.get(i).getAmount() * RuntimeSettings.TICKETFEE * .01);
				ticketpojo.get(i).setQuantityleft(ticketpojo.get(i).getQuantity() - 
						ticketmodel.getbookedtikcetquantity(ticketpojo.get(i).getTicketid()));
				Date date = new Date();
				ticketpojo.get(i).setDaysleftfortktenddate((Days.daysBetween(new DateTime(date), new DateTime(ticketpojo.get(i).getEnddate()))).getDays());
			    //System.out.println(ticketpojo.get(i).getDaysleftfortktenddate());
			}
			
			
		}
		
		return SUCCESS;
	}

}
